import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-six-years',
  templateUrl: './six-years.component.html',
  styleUrls: ['./six-years.component.scss']
})
export class SixYearsComponent implements OnInit {
  sixYear: any = [
    {
      year: '2018',
      month: '2'
    },
    {
      year: '2019',
      month: '2'
    },
    {
      year: '2020',
      month: '2'
    },
    {
      year: '2021',
      month: '2'
    },
    {
      year: '2022',
      month: '2'
    },
    {
      year: '2023',
      month: '2'
    },
  ]
  lastDay: any = []
  constructor() { }

  ngOnInit(): void {
    this.test();
  }

  getLastDayofMonth(year: any, month: any) {
    let data = new Date(year, month, 0);
    return data.getFullYear() + "-" + (data.getMonth() + 1 > 9 ? data.getMonth() + 1 : "0" + (data.getMonth() + 1) + "-" + (data.getDate() > 9 ? data.getDate() : "0" + data.getDate)
    );
  }

  test() {
    this.sixYear.forEach((item: any) => {
      let day = this.getLastDayofMonth(item.year, item.month);
      this.lastDay.push({ day: day });
    });

  }
}
